<template>
    <el-container>
        <el-header class="header-tabs">
            <el-tabs type="card" v-model="groupId" @tab-change="tabChange">
                <el-tab-pane label="JIT母单" name="-2"></el-tab-pane>
                <el-tab-pane label="待通知发货" name="-1"></el-tab-pane>
                <el-tab-pane label="待发货管理" name="0"></el-tab-pane>
                <el-tab-pane label="已发货管理" name="1"></el-tab-pane>
                <el-tab-pane label="已退货管理" name="8"></el-tab-pane>
                <el-tab-pane label="已入库管理" name="3"></el-tab-pane>
            </el-tabs>
        </el-header>
        <!-- JIT母单 -->
        <el-header v-if="groupId== -2">
            <div class="right-panel-search">
                <div class="search-input"></div>
                <el-input v-model="search.keyword" placeholder="工厂货号/SKC/SPU" clearable @change="handleKeyDown" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.order_no" placeholder="请输入订单号" clearable @change="handleKeyDown" />
                <div class="search-input">客户</div>
                <el-select v-model="search.custom_id" filterable placeholder="请选择客户" clearable @change="cusChange" multiple collapse-tags>
                    <el-option v-for="item in customerList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                </el-select>
                <el-date-picker v-model="search.time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size"  />
                <el-select v-model="search.type" filterable placeholder="首单/加单" clearable>
                    <el-option label="首单" :value="0"/>
                    <el-option label="加单" :value="1"/>
                </el-select>
                <el-select v-model="printProject" filterable placeholder="打印项目" clearable @change="printChange" :disabled="selection.length==0">
                    <el-option label="工艺单" :value="0"/>
                    <el-option label="拣货单" :value="1"/>
                    <el-option label="商品条码" :value="2"/>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding" v-if="groupId== -2">
            <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" show-summary :params="querys">
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="订单号" fixed align="center" width="160">
                    <template #default="scope">
                        <div>{{scope.row.order_no}}</div>
                        <div>{{scope.row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="scope">
                        <div class="shopInfo">
                            <el-image class="img" :src="scope.row.goods.goods_image" :preview-src-list="scope.row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                            <div class="right">
                                <div>工厂货号：{{scope.row.factory_number}}</div>
                                <div>批次号：{{scope.row.batch_number}}</div>
                                <div>SKC：{{scope.row.skc}}</div>
                                <div>商品品牌：{{scope.row.brand_name}}</div>
                                <div>客户：{{scope.row.custom_name}}</div>
                                <div>颜色：{{scope.row.goods.colour}}</div>
                                <div v-if="scope.row.sizeCate">商品类别：{{scope.row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单工厂" prop="apply_name" align="center" width="100" column-key="order_factory_id" :filters="applyFilters">
                    <template #default="scope">
                        <div>{{scope.row.apply_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="尺寸" prop="goods_size" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单数量" prop="total_count" align="center" width="100" :summary="true">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="已要求发货" prop="ask_arrival_count" align="center" width="100" :summary="true">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.ask_arrival_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="未要求发货" prop="no_ask_arrival_count" align="center" width="100" :summary="true">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.no_ask_arrival_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="入库数量" prop="stored_count" align="center" width="100" :summary="true">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.stored_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="退货数量" prop="return_count" align="center" width="100" :summary="true">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.return_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单总数" prop="total_count" align="center" width="100" :show-summary="true"></el-table-column>
                <el-table-column label="下单价格" prop="factory_money" align="center" width="100"></el-table-column>
                <el-table-column label="订单交期" align="center" width="100">
                    <template #default="scope">
                            {{scope.row.deliver_time}}
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center" width="100">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="100">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <div v-if="applyJit">
                                <sc-status-indicator type="danger" v-if="scope.row.is_print == 0"></sc-status-indicator>
                                <el-button text type="primary" size="small" @click="jitPrint(scope.row, scope.$index)" v-auth="'applyJit.sheet'">工艺单</el-button>
                            </div>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <!-- 待通知发货 -->
        <el-header v-if="groupId== -1">
            <div class="right-panel-search">
                <div class="search-input"></div>
                <el-input v-model="search.keyword" placeholder="工厂货号/SKC/SPU" clearable @change="handleKeyDown" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.order_no" placeholder="请输入订单号" clearable @change="handleKeyDown" />
                <div class="search-input">客户</div>
                <el-select v-model="search.custom_id" filterable placeholder="请选择客户" clearable @change="cusChange" multiple collapse-tags>
                    <el-option v-for="item in customerList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                </el-select>
                <el-date-picker v-model="search.time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size"  />
                <el-select v-model="printProject" filterable placeholder="打印项目" clearable @change="printChange" :disabled="selection.length==0">
                    <el-option label="工艺单" :value="0"/>
                    <el-option label="拣货单" :value="1"/>
                    <el-option label="商品条码" :value="2"/>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding" v-if="groupId== -1">
            <scTable ref="table" :apiObj="waitApiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" show-summary :params="queryss">
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="母订单号" fixed  align="center" width="160">
                    <template #default="scope">
                            <div>{{scope.row.order_no}}</div>
                            <div>{{scope.row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="scope">
                        <div class="shopInfo">
                            <el-image class="img" :src="scope.row.goods.goods_image" :preview-src-list="scope.row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                            <div class="right">
                                <div>工厂货号：{{scope.row.factory_number}}</div>
                                <div>批次号：{{scope.row.batch_number}}</div>
                                <div>SKC：{{scope.row.skc}}</div>
                                <div>商品品牌：{{scope.row.brand_name}}</div>
                                <div>客户：{{scope.row.custom_name}}</div>
                                <div>颜色：{{scope.row.goods.colour}}</div>
                                <div v-if="scope.row.sizeCate">商品类别：{{scope.row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单工厂" prop="linkman" align="center" width="100">
                    <template #default="scope">
                        <div>{{scope.row.apply_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="尺寸" prop="goods_size" align="center" width="120">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="未要求发货" prop="no_ask_total" align="center" width="140">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.no_ask_arrival_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="未要求发货合计" prop="no_ask_total" align="center" width="140"></el-table-column>
                <!-- <el-table-column label="入库数量" prop="stored_num" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.stored_num}}
                        </div>
                    </template>
                </el-table-column> -->
                <el-table-column label="工厂价格" prop="factory_money" align="center"></el-table-column>
                <el-table-column label="订单交期" align="center" sortable>
                    <template #default="scope">
                            {{scope.row.deliver_time}}
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="100">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <div v-if="applyWait">
                                <sc-status-indicator type="danger" v-if="scope.row.is_print == 0"></sc-status-indicator>
                                <el-button text type="primary" size="small" @click="jitPrint(scope.row, scope.$index)" v-auth="'applyWait.sheet'">工艺单</el-button>
                            </div>
                            <!-- <el-button text type="primary" size="small" @click="jitPrint(scope.row, scope.$index)" v-auth="'applyWait.sheet'">工艺单</el-button> -->
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <!-- 待发货管理 -->
        <el-header v-if="groupId==0">
            <div class="right-panel-search">
                <div class="search-input"></div>
                <el-input v-model="search.keyword" placeholder="工厂货号/SKC/SPU" clearable @change="handleKeyDown" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.order_no" placeholder="请输入订单号" clearable @change="handleKeyDown" />
                <div class="search-input">子订单号</div>
                <el-input v-model="search.child_order_no" placeholder="请输入子订单号" clearable @change="handleKeyDown" />
                <div class="search-input">客户</div>
                <el-select v-model="search.custom_id" filterable placeholder="请选择客户" clearable @change="cusChange">
                    <el-option v-for="item in customerList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                </el-select>
                <el-date-picker v-model="search.time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size"  />
            </div>
        </el-header>
        <el-header v-if="groupId==0">
            <div class="right-panel-search">
                <el-select v-model="printProject" filterable placeholder="打印项目" clearable @change="printChange" :disabled="selection.length==0">
                    <el-option label="工艺单" :value="3"/>
                    <el-option label="拣货单" :value="4"/>
                    <el-option label="商品条码" :value="5"/>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                <el-button type="primary" :disabled="selection.length==0" v-auth="'applyWaitshipped.sendoutAll'" @click="sendAll()">批量发货</el-button>
            </div>
        </el-header>
        <el-main class="nopadding" v-if="groupId==0">
            <scTable ref="table" :apiObj="statueApiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="query" show-summary>
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="母订单号" fixed align="center" width="150">
                    <template #default="scope">
                        <div v-for="item in scope.row.master_order" :key="item.id">
                            <div>{{item.order_no}}</div>
                            <div>{{item.create_time}}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="子订单号" fixed align="center" width="150">
                    <template #default="scope">
                        <div>{{scope.row.order_no}}</div>
                        <div>{{scope.row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="scope">
                        <div class="shopInfo" v-if="scope.row.goods" >
                            <el-image class="img" :src="scope.row.goods.goods_image" :preview-src-list="scope.row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                            <div class="right">
                                <div>工厂货号：{{scope.row.factory_number}}</div>
                                <div>批次号：{{scope.row.batch_number}}</div>
                                <div>SKC：{{scope.row.skc}}</div>
                                <div>商品品牌：{{scope.row.brand_name}}</div>
                                <div>客户：{{scope.row.custom_name}}</div>
                                <div>颜色：{{scope.row.goods.colour}}</div>
                                <div v-if="scope.row.sizeCate">商品类别：{{scope.row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单工厂" prop="linkman" align="center" width="100">
                    <template #default="scope">
                        <div>{{scope.row.apply_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="尺寸" prop="goods_size" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="分单数量" prop="total_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="工厂价格" prop="factory_money" align="center"></el-table-column>
                <el-table-column label="订单交期" align="center" sortable>
                    <template #default="scope">
                            {{scope.row.deliver_time}}
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="120">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <div v-if="applyWaitshipped">
                                <sc-status-indicator type="danger" v-if="scope.row.is_print == 0"></sc-status-indicator>
                                <el-button text type="primary" size="small" @click="waitshippedPrint(scope.row, scope.$index)" v-auth="'applyWaitshipped.sheet'">工艺单</el-button>
                            </div>
                            <el-button text type="primary" size="small" @click="sendOut(scope.row, scope.$index)" v-auth="'applyWaitshipped.sendout'">发货</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <!-- 已发货管理 -->
        <el-header v-if="groupId==1">
            <div class="right-panel-search">
                <div class="search-input"></div>
                <el-input v-model="search.keyword" placeholder="工厂货号/SKC/SPU" clearable @change="handleKeyDown" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.order_no" placeholder="请输入订单号" clearable @change="handleKeyDown" />
                <div class="search-input">子订单号</div>
                <el-input v-model="search.child_order_no" placeholder="请输入子订单号" clearable @change="handleKeyDown" />
                <div class="search-input">客户</div>
                <el-select v-model="search.custom_id" filterable placeholder="请选择客户" clearable @change="cusChange">
                    <el-option v-for="item in customerList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                </el-select>
                <el-date-picker v-model="search.time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size"  />
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding" v-if="groupId==1">
            <scTable ref="table" :apiObj="statueApiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="query" show-summary>
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="母订单号" fixed prop="master_order" align="center" width="150">
                    <template #default="scope">
                        <div v-for="item in scope.row.master_order" :key="item.id">
                            <div>{{item.order_no}}</div>
                            <div>{{item.create_time}}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="子订单号" fixed align="center" width="150">
                    <template #default="scope">
                        <div>{{scope.row.order_no}}</div>
                        <div>{{scope.row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="scope">
                        <div class="shopInfo" v-if="scope.row.goods">
                            <el-image class="img" :src="scope.row.goods.goods_image" :preview-src-list="scope.row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                            <div class="right">
                                <div>工厂货号：{{scope.row.factory_number}}</div>
                                <div>批次号：{{scope.row.batch_number}}</div>
                                <div>SKC：{{scope.row.skc}}</div>
                                <div>商品品牌：{{scope.row.brand_name}}</div>
                                <div>客户：{{scope.row.custom_name}}</div>
                                <div>颜色：{{scope.row.goods.colour}}</div>
                                <div v-if="scope.row.sizeCate">商品类别：{{scope.row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单工厂" prop="linkman" align="center" width="100">
                    <template #default="scope">
                        <div>{{scope.row.apply_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="尺寸" prop="goods_size" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单数量" prop="total_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="已发货数量" prop="send_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.ask_arrival_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="工厂价格" prop="factory_money" align="center"></el-table-column>
                <el-table-column label="订单交期" align="center" sortable>
                    <template #default="scope">
                            {{scope.row.deliver_time}}
                    </template>
                </el-table-column>
                <el-table-column label="发货时间" align="center">
                    <template #default="scope">
                            {{scope.row.shipped_time}}
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <!-- 已退货管理 -->
        <el-header v-if="groupId==8">
            <el-tabs type="card" v-model="groupIds" @tab-change="tabChanges">
                <el-tab-pane label="退货中" name="8"></el-tab-pane>
                <el-tab-pane label="已完成退货" name="9"></el-tab-pane>
                <el-tab-pane label="退货原因分析" name="2"></el-tab-pane>
            </el-tabs>
        </el-header>
        <el-header v-if="groupId==8">
            <div class="right-panel-search">
                <div class="search-input"></div>
                <el-input v-model="search.keyword" placeholder="工厂货号/SKC/SPU" clearable @change="handleKeyDown" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.order_no" placeholder="请输入订单号" clearable @change="handleKeyDown" />
                <div class="search-input">子订单号</div>
                <el-input v-model="search.child_order_no" placeholder="请输入子订单号" clearable @change="handleKeyDown" />
                <div class="search-input">客户</div>
                <el-select v-model="search.custom_id" filterable placeholder="请选择客户" clearable @change="cusChange">
                    <el-option v-for="item in customerList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                </el-select>
                <el-date-picker v-model="search.time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size"  />
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding" v-if="groupId==8">
            <scTable ref="table" :apiObj="statueApiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="query" show-summary>
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="母订单号" fixed prop="master_order" align="center" width="150">
                    <template #default="scope">
                        <div v-for="item in scope.row.master_order" :key="item.id">
                            <div>{{item.order_no}}</div>
                            <div>{{item.create_time}}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="子订单号" fixed align="center" width="150">
                    <template #default="scope">
                        <div>{{scope.row.order_no}}</div>
                        <div>{{scope.row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="scope">
                        <div class="shopInfo">
                            <el-image class="img" :src="scope.row.goods.goods_image" :preview-src-list="scope.row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                            <div class="right">
                                <div>工厂货号：{{scope.row.factory_number}}</div>
                                <div>批次号：{{scope.row.batch_number}}</div>
                                <div>SKC：{{scope.row.skc}}</div>
                                <div>商品品牌：{{scope.row.brand_name}}</div>
                                <div>客户：{{scope.row.custom_name}}</div>
                                <div>颜色：{{scope.row.goods.colour}}</div>
                                <div v-if="scope.row.sizeCate">商品类别：{{scope.row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单工厂" prop="linkman" align="center" width="100">
                    <template #default="scope">
                        <div>{{scope.row.apply_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="尺寸" prop="goods_size" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单数量" prop="total_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="发货数量" prop="send_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.ask_arrival_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="退货数量" prop="return_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.return_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="工厂价格" prop="factory_money" align="center"></el-table-column>
                <el-table-column label="订单交期" align="center" sortable>
                    <template #default="scope">
                            {{scope.row.deliver_time}}
                    </template>
                </el-table-column>
                <el-table-column label="退货时间" align="center" v-if="groupId==8">
                    <template #default="scope">
                            {{scope.row.arrived_time}}
                    </template>
                </el-table-column>
                <el-table-column label="退货时间" align="center" v-if="groupId==9">
                    <template #default="scope">
                            {{scope.row.repair_time}}
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="80">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <el-button text type="primary" size="small" @click="returns(scope.row, scope.$index)" v-auth="'applyReturn.reason'">查看报告</el-button>
                            <el-button text type="primary" size="small" @click="fan(scope.row, scope.$index)" v-auth="'applyReturn.fan'" v-if="groupIds==8">返修入库</el-button>
                            <el-button text type="primary" size="small" @click="original(scope.row, scope.$index)" v-auth="'applyReturn.original'" v-if="groupIds==8">原单发货</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <!-- 已入库管理 -->
        <el-header v-if="groupId==3">
            <div class="right-panel-search">
                <div class="search-input"></div>
                <el-input v-model="search.keyword" placeholder="工厂货号/SKC/SPU" clearable @change="handleKeyDown" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.order_no" placeholder="请输入订单号" clearable @change="handleKeyDown" />
                <div class="search-input">子订单号</div>
                <el-input v-model="search.child_order_no" placeholder="请输入子订单号" clearable @change="handleKeyDown" />
                <div class="search-input">客户</div>
                <el-select v-model="search.custom_id" filterable placeholder="请选择客户" clearable @change="cusChange">
                    <el-option v-for="item in customerList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                </el-select>
                <el-date-picker v-model="search.time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size"  />
            </div>
        </el-header>
        <el-header v-if="groupId==3">
            <div class="right-panel-search">
                <div class="search-input">状态</div>
                <el-select v-model="search.is_bill" placeholder="状态" clearable>
                    <el-option label="未生成" :value="0"/>
                    <el-option label="已生成" :value="1"/>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding" v-if="groupId==3">
            <scTable ref="table" :apiObj="statueApiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="que" show-summary>
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="母订单号" fixed prop="master_order" align="center" width="150">
                    <template #default="scope">
                        <div v-for="item in scope.row.master_order" :key="item.id">
                            <div>{{item.order_no}}</div>
                            <div>{{item.create_time}}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="子订单号" fixed align="center" width="150">
                    <template #default="scope">
                        <div>{{scope.row.order_no}}</div>
                        <div>{{scope.row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="scope">
                        <div class="shopInfo" v-if="scope.row.goods">
                            <el-image class="img" :src="scope.row.goods.goods_image" :preview-src-list="scope.row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                            <div class="right">
                                <div>工厂货号：{{scope.row.factory_number}}</div>
                                <div>批次号：{{scope.row.batch_number}}</div>
                                <div>SKC：{{scope.row.skc}}</div>
                                <div>商品品牌：{{scope.row.brand_name}}</div>
                                <div>客户：{{scope.row.custom_name}}</div>
                                <div>颜色：{{scope.row.goods.colour}}</div>
                                <div v-if="scope.row.sizeCate">商品类别：{{scope.row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单工厂" fixed prop="linkman" align="center" width="100">
                    <template #default="scope">
                        <div>{{scope.row.apply_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="尺寸" fixed prop="goods_size" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="下单数量" fixed prop="total_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="发货数量" fixed prop="send_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.shipped_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="入库数量" prop="stored_count" align="center" width="100">
                    <template #default="scope">
                        <div v-for="(item,index) in scope.row.orderDetail" :key="index">
                            {{item.stored_num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="工厂价格" prop="factory_money" align="center"></el-table-column>
                <el-table-column label="订单交期" align="center" sortable>
                    <template #default="scope">
                            {{scope.row.deliver_time}}
                    </template>
                </el-table-column>
                <el-table-column label="入库时间" align="center">
                    <template #default="scope">
                            {{scope.row.arrived_time}}
                    </template>
                </el-table-column>
                <el-table-column label="状态" align="center" width="100">
                    <template #default="scope">
                        <el-tag v-if="scope.row.is_bill==1" type="success">已生成</el-tag>
                        <el-tag v-else type="danger">未生成</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <print ref="pitDialog"></print><!-- 打印 -->
    <send-out v-if="dialog.send" ref="sendDialog" @success="handleSuccess" @closed="dialog.send = false" draggable></send-out><!-- 待发货点击发货 -->
    <return v-if="dialog.ret" ref="retDialog" @success="handleSuccess" @closed="dialog.ret = false" draggable></return><!-- 已退货退货原因 -->
    <repair v-if="dialog.fan" ref="fanDialog" @success="handleSuccess" @closed="dialog.fan = false" draggable></repair><!-- 已退货返修 -->
    <original v-if="dialog.orig" ref="origDialog" @success="handleSuccess" @closed="dialog.orig = false" draggable></original><!-- 已退货原单发货 -->
    <print-gong v-if="dialog.print" ref="printDialog" @success="handleSuccess" @closed="dialog.print = false" draggable></print-gong>
    <print-jian v-if="dialog.jian" ref="jianDialog" @success="handleSuccess" @closed="dialog.jian = false" draggable></print-jian>
    <el-dialog v-model="dialog.sort" title="请选择打印排序" width="500" :before-close="handleClose" align-center>
        <el-radio-group v-model="jianType" class="ml-4" @change="radioChange">
            <el-radio label="1" size="large">按库位排序</el-radio>
            <el-radio label="2" size="large">按货号排序</el-radio>
            <el-radio label="3" size="large">按下单时间排序</el-radio>
            <el-radio label="4" size="large">按到期时间排序</el-radio>
        </el-radio-group>
    </el-dialog>
</template>

<script>
import jitOrder from './jitOrder.vue'
import Print from '../print.vue'
import SendOut from './sendOut.vue'
import Return from './return.vue'
import Repair from './repair.vue'
import Original from './original.vue'
import PrintGong from '../factoryOrder/printGong.vue'
import PrintJian from '../factoryOrder/printJian.vue'
export default {
    components: { jitOrder,   Print, SendOut,  Return, Repair, Original, PrintGong, PrintJian },
	name: '生产订单',
	data() {
		return {
			dialog: {
                pit:false,
                send:false,
                ret:false,
                fan:false,
                orig:false,
                print:false,
                sort:false,
                jian:false,
			},
			groupFilterText: '',
			group: [],
			apiObj: this.$API.order.getOrder.lists,
            querys:{
                is_supplier:1,
            },
            que:{
                is_supplier:1,
                is_bill:0,
                status:3,
            },
            waitApiObj:this.$API.order.getOrder.waitNoticeOrder,
            queryss:{
                is_supplier:1,
            },
            statueApiObj:this.$API.order.getOrder.waitOrderList,
            query:{
                status:"",
                is_supplier:1,
            },
			selection: [],
			search: {
                order_no:"",
				keyword: "",
				brand_id: "",
				time: [],
                apply_id:"",
                custom_id:"",
                type:"",
			},
			//所需数据选项
            customerList:[],
            orderArr:[],
            customName: false,
            applyName:false,
            taks:false,
            groupId:"-2",
            groupIds:"8",
            printProject:'',
            orderStatus:'',
            jianType:"",
            applyFilters:[],
            applyJit:this.$TOOL.data.get("PERMISSIONS").includes('applyJit.sheet'),
            applyWait:this.$TOOL.data.get("PERMISSIONS").includes('applyWait.sheet'),
            applyWaitshipped:this.$TOOL.data.get("PERMISSIONS").includes('applyWaitshipped.sheet'),
		}
	},
	mounted() {
        this.getApply()
        this.getKeHu()
	},
	methods: {
        async getApply() {
            var res = await this.$API.all.Apply.get({type:1});
			let a = []
			res.data.map(item => {
				a.push({
					text: item.apply_name,
					value: item.apply_id,
				})
			})
			this.applyFilters = a
		},
        // jit打印
        async jitPrint(row){
            var reqData = { order_no_arr: row.order_no };
            var res = await this.$API.print.orderPrintAll.get(reqData);
			if (res.code == 1) {
                this.dialog.print = true;
                setTimeout(()=>{
                    this.$refs.printDialog.open("edit").setData(res.data.template_data);
                },500)
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
        },
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        selectionChange(selection) {
			this.selection = selection;
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			} else if (mode == 'over1`') {
				this.$refs.table.refresh()
			}
		},
        // 待发货打印工艺单
        async waitshippedPrint(row){
            var reqData = { order_no_arr: row.order_no };
            var res = await this.$API.print.childPrintAll.get(reqData);
			if (res.code == 1) {
                this.dialog.print = true;
                setTimeout(()=>{
                    this.$refs.printDialog.open("edit").setData(res.data.template_data);
                },500)
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
        },
        // 待发货发货
        sendOut(row){
            this.dialog.send = true;
			this.$nextTick(() => {
				this.$refs.sendDialog.open("over").setData(row);
			});
        },
        // 待发货批量发货
        async sendAll() {
			var order_no_arr = [];
			this.selection.map((item) => {
				order_no_arr.push(item.order_no)
			})
			this.$confirm(`确定批量发货选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(() => {
				this.table_del_all(order_no_arr)
			}).catch(() => {

			})
		},
		async table_del_all(order_no) {
			var reqData = {order_no_arr: order_no}
			var res = await this.$API.order.getOrder.waitOrderSendAll.post(reqData);
			if (res.code == 1) {
				this.$refs.table.refresh()
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
        // 已退货退货原因
        returns(row) {
			this.dialog.ret = true
			this.$nextTick(() => {
				this.$refs.retDialog.open("show").setData(row);
			})
		},
        // 已退货返修
        fan(row) {
			this.dialog.fan = true
			this.$nextTick(() => {
				this.$refs.fanDialog.open("over").setData(row);
			})
		},
        // 已退货原单发货
        original(row) {
			this.dialog.orig = true
			this.$nextTick(() => {
				this.$refs.origDialog.open("over").setData(row);
			})
		},
        // 获取客户
        async getKeHu(){
            var res = await this.$API.all.customer.get();
            this.customerList = res.data;
        },
        tabChange(e){
            this.groupId = e
            this.query.status = e
            this.search.order_no=null,
            this.search.keyword= null,
            this.search.brand_id= null,
            this.search.time= null,
            this.search.apply_id=null,
            this.search.custom_id=null,
            this.search.child_order_no=null
            // this.query.status = 0
            this.printProject = ''
            if(e==3){
                this.search.is_bill = 0
            }
        },
        // 已退货的切换
        tabChanges(e){
            this.groupIds = e
            this.query.status=e
            this.$refs.table.upData(this.search)
        },
        handleKeyDown() {
            this.upsearch()
        },
        async printChange(e){
            let ids = []
            this.selection.map(item=>{
                ids.push(item.order_no)
            })
            if(e==0){
                var reqData = { order_no_arr:ids };
                var res = await this.$API.print.orderPrintAll.get(reqData);
                if (res.code == 1) {
                    // this.$refs.pitDialog.init(res.data);
                    this.dialog.print = true;
                    setTimeout(()=>{
                        this.$refs.printDialog.open("add").setData(res.data.template_data);
                    },500)
                    this.printArr = ''
                } else {
                    this.$alert(res.message, "提示", { type: "error" });
                }
            }
            if(e==1){
                this.jianPrint(e)
            }
            if(e==3){
                var reqDatas = { order_no_arr:ids };
                var a = await this.$API.print.childPrintAll.get(reqDatas);
                if (a.code == 1) {
                    this.dialog.print = true;
                    setTimeout(()=>{
                        this.$refs.printDialog.open("add").setData(a.data.template_data);
                    },500)
                    this.printArr = ''
                } else {
                    this.$alert(a.message, "提示", { type: "error" });
                }
            }
            if(e==4){
                this.jianPrint(e)
            }
        },
        // 拣货单打印
        async jianPrint(e){
            this.orderStatus = e
            this.dialog.sort = true
        },
        async radioChange(e){
            var ids = [];
            this.selection.forEach((item) => {
				ids.push(item.order_no)
			})
            var reqData = { order_no_arr : ids,order_sort:e};
            let a = this.groupId
            var res = await this.$API.print[a==0?'getPickingListChild':'getPickingList'].get(reqData);
			if (res.code == 1) {
                this.dialog.sort = false;
                this.dialog.jian = true;
                setTimeout(()=>{
                    if(this.orderStatus==1){
                        this.$refs.jianDialog.open("jit").setData(res.data);
                    }else if(this.orderStatus==2){
                        this.$refs.jianDialog.open("tong").setData(res.data);
                    }else if(this.orderStatus==3){
                        this.$refs.jianDialog.open("wait").setData(res.data);
                    }else if(this.orderStatus==4){
                        this.$refs.jianDialog.open("wait").setData(res.data);
                    }
                },500)
                this.jianType = ''
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
        },
	}
}
</script>

<style lang="scss">
</style>
